package com.chuangmei.com.arindoorlocationsystem.utils;

import android.annotation.SuppressLint;
import android.app.AlertDialog;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.view.View;
import android.view.Window;

import com.chuangmei.com.arindoorlocationsystem.R;

/**
 * 项目名称：ARIndoorLocationSystem
 * 类描述：
 * 创建人：LuoHao
 * 创建时间：2018/4/20 11:23
 * 修改人：LuoHao
 * 修改时间：2018/4/20 11:23
 * 修改备注：
 */

public class DialogUtils {

    /**
     * 普通对话框
     *
     * @param context
     * @param titleResId
     * @param messageResId
     * @param cancelable
     * @param yesOnClick
     * @param noOnClick
     */
    public static void showDialog(Context context, int titleResId, int messageResId, boolean cancelable,
                                  DialogInterface.OnClickListener yesOnClick,
                                  DialogInterface.OnClickListener noOnClick) {
        AlertDialog dialog = new AlertDialog.Builder(context).setTitle(titleResId)
                .setMessage(messageResId).setCancelable(cancelable)
                .setPositiveButton("yes", yesOnClick).setNegativeButton("no", noOnClick).create();
        dialog.show();

    }

    /**
     * 无title对话框
     *
     * @param context
     * @param messageResId
     * @param cancelable
     * @param yesOnClick
     * @param noOnClick
     */
    public static void showNoTitleDialog(Context context, int messageResId, boolean cancelable,
                                         DialogInterface.OnClickListener yesOnClick,
                                         DialogInterface.OnClickListener noOnClick) {
        AlertDialog dialog = new AlertDialog.Builder(context)
                .setMessage(messageResId).setCancelable(cancelable)
                .setPositiveButton("确定", yesOnClick).setNegativeButton("取消", noOnClick).create();
        dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);//这句话，就是决定上面的那个黑框，也就是dialog的title。
        dialog.show();

    }

    /**
     * 无title对话框
     *
     * @param context
     * @param message
     * @param cancelable
     * @param yesOnClick
     * @param noOnClick
     */
    public static void showNoTitleDialog(Context context, String message, boolean cancelable,
                                         DialogInterface.OnClickListener yesOnClick,
                                         DialogInterface.OnClickListener noOnClick) {
        AlertDialog dialog = new AlertDialog.Builder(context)
                .setMessage(message).setCancelable(cancelable)
                .setPositiveButton("确定", yesOnClick).setNegativeButton("取消", noOnClick).create();
        dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);//这句话，就是决定上面的那个黑框，也就是dialog的title。
        dialog.show();

    }

    /**
     * 自定义View
     *
     * @param context
     * @param titleResId
     * @param v
     * @param cancelable
     */
    public static void showDialog(Context context, int titleResId, View v, boolean cancelable) {
        AlertDialog dialog = new AlertDialog.Builder(context)
                .setTitle(titleResId).setView(v).setCancelable(cancelable)
                .setPositiveButton("yes", null).create();
        dialog.show();
    }

    /**
     * 单选对话框
     *
     * @param context
     * @param titleResId
     * @param arrayId
     * @param choiceOnClickListener
     */
    public static void showMultiItemsDialog(Context context, int titleResId, int arrayId,
                                            DialogInterface.OnClickListener choiceOnClickListener) {
        AlertDialog dialog = new AlertDialog.Builder(context).setTitle(titleResId)
                .setSingleChoiceItems(arrayId, -1, choiceOnClickListener).setCancelable(true).create();
        dialog.show();
    }

    /**
     * 等待动画dialog
     *
     * @param m
     * @return
     */
    @SuppressLint("ResourceType")
    public static ProgressDialog createProgress(String string, Context m) {
        ProgressDialog dialog = new ProgressDialog(m);
        dialog.getWindow().setWindowAnimations(R.drawable.anim_progress);
        dialog.setMessage(string);
        dialog.setIndeterminate(false);
        dialog.setCancelable(true);
        return dialog;
    }
}
